#!/usr/bin/env python

"""
    Flowblade Movie Editor is a nonlinear video editor.
    Copyright 2012 Janne Liljeblad.

    This file is part of Flowblade Movie Editor <http://code.google.com/p/flowblade>.

    Flowblade Movie Editor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Flowblade Movie Editor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Flowblade Movie Editor.  If not, see <http://www.gnu.org/licenses/>.
"""

import os
import sys

print "FLOWBLADE MOVIE EDITOR 0.11 TRUNK"
print "---------------------------------"

# Get launch script dir
launch_dir = os.path.dirname(os.path.abspath(sys.argv[0]))

print "Launch script dir:", launch_dir

# Update sys.path to include modules
if launch_dir == "/usr/bin":
    print "Running from installation..."
    modules_path = "/usr/share/pyshared/Flowblade"
else:
    print "Running from filesystem..."
    modules_path = launch_dir + "/Flowblade"
sys.path.insert(0, modules_path)
sys.path.insert(0, modules_path + "/vieweditor")
sys.path.insert(0, modules_path + "/tools")

# Check that we have MLT, missing is fatal.
try:
    import mlt
    try:
        mlt_version = mlt.LIBMLT_VERSION
        print "MLT found, version:", mlt_version
    except:
        print "MLT found but version info not available. MLT probably too old to work reliably..."
except Exception, err:
    print "MLT not found, exiting..."
    print "ERROR:", err
    sys.exit(1)
  
# Get app.py module and set info which type of installation is running
try:
    import app
    import editorstate
    if launch_dir == "/usr/bin":
        editorstate.app_running_from = editorstate.RUNNING_FROM_INSTALLATION
    else:
        editorstate.app_running_from = editorstate.RUNNING_FROM_DEV_VERSION
except Exception, err:
    print "Failed to import module app.py to launch Flowblade!"
    print "ERROR:", err
    print "Installation was assumed to be at:", modules_path
    sys.exit(1)


# Launch application
app.main(modules_path)
